<?php

use yii\helpers\Html;
use yii\grid\GridView;
use common\models\CommentStatus;

/* @var $this yii\web\View */
/* @var $searchModel common\models\CommentSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '评论管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="comment-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [

            ['attribute'=>'id',
             'contentOptions'=>['width'=>'30px'],
            ],
            ['attribute'=>'content',
             'value'=>'contentHeading'
            ],
            ['attribute'=>'user.username',
                    'label'=>'用户',
                    'value'=>'user.username',
            ],
            ['attribute'=>'status',
             'value'=>'commentStatus.name',
             'filter'=>CommentStatus::getStatusItems(),
             'contentOptions'=>
                function($model)
                {
                    return ($model->status==1)?['class'=>'bg-danger']:[];
                },
            ],
            ['attribute'=>'create_time',
             'format'=>['date','php:Y年m月d日 H:i:s'],
            ],
            // 'email:email',
            // 'url:url',
            // 'post_id',
            ['attribute'=>'post.title',
             'label'=>'文章标题',
            ],

            ['class' => 'yii\grid\ActionColumn',
             'template'=>'{view} {update} {delete} {approve}',
             'buttons'=>
                ['approve'=>function ($url, $model, $key) {
                    $title = Yii::t('yii', '审核');
                    $options=[
                        'title' => $title,
                        'aria-label' => $title,
                        'data-pjax' => '0',
                        'data-confirm' => Yii::t('yii', '审核通过这条评论?'),
                        'data-method' => 'post',
                    ];
                    return Html::a('<span class="glyphicon glyphicon-check"></span>', $url, $options);
                 }
                ],
            ],
        ],
    ]); ?>
</div>
